package com.itheima.exerciseTest.test40_49;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class Test46 {
    public static void main(String[] args) {
        File file = new File("backBurner");
        Map<String, Integer> hm = get(file);
        System.out.println(hm);
    }

    public static Map<String, Integer> get(File fist) {
        HashMap<String, Integer> hm = new HashMap<>();
        get(fist, hm);
        return hm;
    }

    public static void get(File fist, Map<String, Integer> hm) {
        File[] files = fist.listFiles();
        for (File f : files) {
            if (f.isFile()) {
                String fileName = f.getName();
                String[] split = fileName.split("\\.");
                String fileEndName = split[split.length - 1];
                if (hm.containsKey(fileEndName)) {
                    Integer count = hm.get(fileEndName);
                    count++;
                    hm.put(fileEndName, count);
                } else {
                    hm.put(fileEndName, 1);
                }
            } else {
                get(f, hm);
            }
        }
    }
}
